﻿describe("Strategies/NakedSingle", function () {

    var nakedSingle;

    beforeEach(function () {
        nakedSingle = new Strategies.NakedSingle();
    });

    it("should find single", function () {
        var expectedShortString = "---16-42---2---8-5--5--36-9----5-18-----------96-7----1-89--3--4-9---7---5--16---";
        var gridModel = GridModel.fromShortString("---16--2---2---8-5--5--36-9----5-18-----------96-7----1-89--3--4-9---7---5--16---");
        SolvingHelper.fillCandidates(gridModel);

        //do
        var performResult = nakedSingle.perform(gridModel);

        //expect
        expect(performResult).toBeTruthy();
        expect(performResult).toEqual(gridModel.cells[0][6]);
        expect(expectedShortString).toEqual(gridModel.toShortString());
    });

    it("should complete this grid in 32 iterations", function () {
        var expectedShortString = "716392854839456127542817936268935741951764283374281695185649372623578419497123568";
        var gridModel = GridModel.fromShortString("716-92-5-839456--754281-9-626-9-5741951-----33742-169---5--93--6235-8--9-9--2--6-");
        SolvingHelper.fillCandidates(gridModel);

        //do
        var iterations = 0;
        var performed = true;
        while (performed) {
            iterations++;
            performed = nakedSingle.perform(gridModel);
        }

        expect(expectedShortString).toEqual(gridModel.toShortString());
        expect(iterations).toEqual(32);
    });
});
